//package com.cby.user.helper;
//
//import org.springframework.beans.factory.InitializingBean;
//import org.springframework.stereotype.Component;
//
//import java.util.concurrent.LinkedBlockingQueue;
//import java.util.concurrent.ThreadPoolExecutor;
//import java.util.concurrent.TimeUnit;
//
//@Component
//public class TaskExecutor implements InitializingBean {
//
//    private final static int CORE_POOL_SIZE = Runtime.getRuntime().availableProcessors();
//    private final static int MAX_POOL_SIZE = Integer.MAX_VALUE;
//    private final static int KEEP_ALIVE_TIME = 2;
//    private final Object lock = new Object();
//
//
//    private ThreadPoolExecutor threadPool;
//
//
//    public void restart() {
//        synchronized (lock) {
//            boolean shutdown = threadPool.isShutdown();
//            if(shutdown) {
//                init();
//            }
//        }
//    }
//
//
//    public void execute(Runnable runnable) {
//        boolean shutdown = threadPool.isShutdown();
//        if(shutdown) {
//            restart();
//        }
//        threadPool.submit(runnable);
//    }
//
//
//
//
//    public void shutdown() {
//        try {
//            threadPool.awaitTermination(10, TimeUnit.MINUTES);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
//        threadPool.shutdown();
//    }
//
//
//    private void init(){
//        threadPool =  new ThreadPoolExecutor(CORE_POOL_SIZE, MAX_POOL_SIZE,KEEP_ALIVE_TIME,
//                TimeUnit.SECONDS,new LinkedBlockingQueue<>());
//    }
//
//    @Override
//    public void afterPropertiesSet() throws Exception {
//        init();
//    }
//}
